{include file="public/header"}

<body>

	<section id="container" class="">
		<!--header start-->
		{include file="public/headtop" /}
		<!--header end-->
		<!--sidebar start-->
		<aside>
			<div id="sidebar"  class="nav-collapse ">
				<!-- sidebar menu start-->
				{include file="public/menu" /}
				<!-- sidebar menu end-->
			</div>
		</aside>
		<!--sidebar end-->
		<!--main content start-->
		<section id="main-content">
			<section class="wrapper site-min-height">
				<!-- page start-->
				<div class="row">
					<div class="col-lg-12">
						{include file="public/nav" webnavname="主机管理"}
					</div>
					<div class="col-lg-6">
						<div class="btn-group">
							<!-- <button id="editable-sample_new" class="btn green success" data-toggle="modal" href="#incHost">
								新增主机 <i class="fa fa-plus"></i>
							</button> -->
							<a  class="btn green success" href="/admin/inc.html">
								新增主机 <i class="fa fa-plus"></i>
							</a>
						</div>
						
					</div>
					<div class="col-lg-6">
						<input type="text"  class="form-control medium" id="search" placeholder="搜索主机IP，全部请为空">
					</div>
					<div class="col-sm-12">
						<section class="panel">
							<header class="panel-heading">
								主机列表
							</header>
							<table class="table table-hover">
								<thead>
									<tr>
										<th>#</th>
										<th>机名</th>
										<th>IP</th>
										<th>到期时间</th>
										<th>费用/月</th>
										<th>状态</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>

									{volist name="hostList" id="host" empty="当前没有添加服务器"}
									<tr id="hostList_{$host.id}">
										<td>{$host.id}</td>
										<td><a href="/admin/edit/{$host.id}.html" title="编辑信息">{$host.name}</a></td>
										<td>{$host.ip}</td>
										<td>{$host.expiretime}</td>
										<td>{$host.money}</td>
										<td><a class="label label-{$host.status ? 'success' : 'danger'}" onclick="hoststatus({$host.id},{$host.status ? '0' : '1'})" title="点击修改状态">{$host.status ? '正常' : '停用'}</a></td>
										<td>
											<a class="btn btn-{$host.hot ? 'danger' : 'success'} btn-xs" {$host.hot ? 'title="取消推荐"' : 'title="设为推荐"'} onclick="hostup({$host.id},{$host.hot ? '0' : '1'})"><i class="fa  fa-arrow-circle-{$host.hot ? 'down' : 'up'}"></i></a>
											
											
											<a class="btn btn-danger btn-xs" href="/admin/delete/{$host.id}.html"><i class="fa fa-trash-o "></i></a>
										</td>
									</tr>
									{/volist}
									
								</tbody>
							</table>
						</section>
					</div>
				</div>
				<div class="row">
					<div class="col-lg-12">
						<section class="panel">
							<input type="hidden" name="HostID" id="HostID">
							<div class="modal fade" id="EchoMsg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
								<div class="modal-dialog modal-sm">
									<div class="modal-content-wrap">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
												<h4 class="modal-title">消息通知</h4>
											</div>
											<div class="modal-body text-center" id="msgVal">

											</div>
											<div class="modal-footer">
												<button class="btn btn-danger" type="button" data-dismiss="modal"> OK</button>
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="modal fade  modal-dialog-center" id="incHost" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
								<div class="modal-dialog">
									<div class="modal-content-wrap">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
												<h4 class="modal-title">新增主机</h4>
											</div>
											<div class="modal-body">

												<form role="form">
													<div class="form-group">
														<label>机名</label>
														<div class="iconic-input">
															<i class="fa fa-tags"></i>
															<input type="text" class="form-control" name="name" id="name" placeholder="机名">
														</div>
													</div>
													<div class="form-group">
														<label>IP</label>
														<div class="iconic-input">
															<i class="fa fa-cloud"></i>
															<input type="text" class="form-control" name="ip" id="host_ip" placeholder="Ip" >
														</div>
													</div>
													<div class="form-group">
														<label>价格</label>
														<div class="iconic-input">
															<i class="fa fa-cny"></i>
															<input type="text" name="money" id="money" placeholder="销售价格"  class="form-control">

														</div>
													</div>
													<div class="form-group">
														<label>服务器到期时间</label>
														<div class="iconic-input">
															<i class="fa fa-clock-o"></i>
															<input type="text" name="expiretime" id="expiretime" placeholder="服务器到期时间" data-mask="9999-99-99" class="form-control">

														</div>
													</div>
													<div class="form-group">
														<label>宝塔地址</label>
														<div class="iconic-input">
															<i class="fa fa-globe"></i>
															<input type="text" class="form-control" name="bturl" id="bturl" placeholder="宝塔地址">
														</div>
													</div>
													<div class="form-group">
														<label>宝塔密钥</label>
														<div class="iconic-input">
															<i class="fa fa-unlock-alt"></i>
															<input type="text" class="form-control" name="btoken" id="btoken" placeholder="宝塔接口密钥">
														</div>
													</div>

												</form>

											</div>
											<div class="modal-footer">
												<button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
												<button class="btn btn-warning" type="button" onclick="inc()"> 新增</button>
											</div>
										</div>
									</div>
								</div>
							</div>
							
						</section>
					</div>
				</div>
				<!-- page end-->
			</section>
		</section>
		<!--main content end-->
		<!-- Right Slidebar start -->
		{include file="public/slidright"}
		<!-- Right Slidebar end -->
		<!--footer start-->
		<footer class="site-footer">
			{include file="public/footer"}
		</footer>
		<!--footer end-->
	</section>

	<!-- js placed at the end of the document so the pages load faster -->
	<script src="__STATIC__/js/jquery.js"></script>
	<script src="__STATIC__/js/bootstrap.min.js"></script>
	<script class="include" type="text/javascript" src="__STATIC__/js/jquery.dcjqaccordion.2.7.js"></script>
	<script src="__STATIC__/js/jquery.scrollTo.min.js"></script>
	<script src="__STATIC__/js/jquery.nicescroll.js" type="text/javascript"></script>
	<script type="text/javascript" src="__STATIC__/assets/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
	<script src="__STATIC__/js/respond.min.js" ></script>
	

	<!--right slidebar-->
	<script src="__STATIC__/js/slidebars.min.js"></script>


	<!--common script for all pages-->
	<script src="__STATIC__/js/common-scripts.js"></script>

	<script>
		function inc(){
			$('#incHost').modal('hide');
			var name = $('#incHost #name').val();
			var ip = $('#incHost #host_ip').val();
			var money = $('#incHost #money').val();
			var expiretime = $('#incHost #expiretime').val();
			var bturl = $('#incHost #bturl').val();
			var btoken = $('#incHost #btoken').val();
			$.post('./host/index',{type:'inc',name:name,ip:ip,money:money,expiretime:expiretime,bturl:bturl,btoken:btoken},function(data){
				if(data.code!=200){
					EchoMsg(data.msg);
				}else{
					EchoMsg(data.msg);
				}
			});
		}
		function update(){
			$('#upHost').modal('hide');
			var id = $('#HostID').val();
			var name = $('#upHost #name_up').val();
			var ip = $('#upHost #host_ip_up').val();
			var money = $('#upHost #money_up').val();
			var expiretime = $('#upHost #expiretime_up').val();
			var bturl = $('#upHost #bturl_up').val();
			var btoken = $('#upHost #btoken_up').val();
			$.post('./host/index',{id:id,type:'update',name:name,ip:ip,money:money,expiretime:expiretime,bturl:bturl,btoken:btoken},function(data){
				if(data.code!=200){
					EchoMsg(data.msg);
				}else{
					EchoMsg(data.msg);
				}
			});
		}
		function getHostInfo(id){
			var a = $('#hostList_'+id+' td');
			var name = a[1].textContent;
			var ip = a[2].textContent;
			var money = a[3].textContent;
			var expiretime = a[4].textContent;
			var bturl = a[5].textContent;
			var btoken = a[6].textContent;
			$('#HostID').val(id);
			$('#incHost #name').val(name);
			$('#incHost #host_ip').val(ip);
			$('#incHost #money').val(money);
			$('#incHost #expiretime').val(expiretime);
			$('#incHost #bturl').val(bturl);
			$('#incHost #btoken').val(btoken);
			$('#upHost').modal('show');
		}
		$(function() {
			$('#search').on('keypress',function(event){
				if(event.keyCode == "13"){  
					window.location.href="?search="+$('#search').val();
				}
			});
		});
		function hostup(hostid,type){
			$.post('', {hot:1,hostid:hostid,type:type}, function(data, textStatus, xhr) {
				if(data.code==200){
					EchoMsg(data.msg,location.href);
				}else{
					EchoMsg('发生错误：'+data.msg,location.href);
				}
			});
		}
		function hoststatus(hostid,type){
			$.post('', {status:1,hostid:hostid,type:type}, function(data, textStatus, xhr) {
				if(data.code==200){
					EchoMsg(data.msg,location.href)
				}else{
					EchoMsg('发生错误：'+data.msg,location.href);
				}
			});
		}
		function EchoMsg(msg,local){
			$('#msgVal').html(msg);
			$('#EchoMsg').modal('show');
			if(local){
				$('#EchoMsg').on('hidden.bs.modal', function () {
					window.location.href = local;
				})
			}
		}
	</script>
</body>
</html>
